﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using SQLHelper;

public partial class admin_Comments : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["del_id"] != null)
        {
            Delete();
        }

        bind();
    }

    // 删除数据
    void Delete()
    {
        int UserID = Master.UserID;
        int id = Convert.ToInt32(Request["del_id"]);
        string sqlstr = "delete from comments where id='" + id + "'";
        DB.GetDataNoQuery(sqlstr);
        DB.ColseSqlCon();
        Response.Redirect("~/admin/Comments.aspx");
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        bind();
    }

    void bind()
    {
        int UserID = Master.UserID;
        string sql = "select c.*,n.title from comments c, news n where c.news_id = n.id";
        DataSet res = DB.GetDataWithQuerySecond(sql, "commnets");
        GridView1.DataSource = res;
        GridView1.DataKeyNames = new string[] { "id" };
        GridView1.DataBind();
        DB.ColseSqlCon();
    }
}